package ch.ethz.systems.netbench.ext.basic;

import ch.ethz.systems.netbench.core.log.SimulationLogger;
import ch.ethz.systems.netbench.core.network.Link;
import ch.ethz.systems.netbench.core.network.NetworkDevice;
import ch.ethz.systems.netbench.core.run.infrastructure.LinkGenerator;

public class PerfectSimpleLinkDifferentLinkDelayGenerator extends LinkGenerator {

    private final long interPodDelayNs;
    private final long intraPodDelayNs;
    private final long bandwidthBitPerNs;

    public PerfectSimpleLinkDifferentLinkDelayGenerator(long interPodDelayNs, long intraPodDelayNs, long bandwidthBitPerNs) {
        this.interPodDelayNs = interPodDelayNs;
        this.intraPodDelayNs = intraPodDelayNs;
        this.bandwidthBitPerNs = bandwidthBitPerNs;
        SimulationLogger.logInfo("Link", 
                                    "PERFECT_SIMPLE_LINK_DIFF_INJECTION(interPodDelayNs=" + 
                                    interPodDelayNs + 
                                    ", intraPodDelayNs=" + 
                                    intraPodDelayNs + 
                                    ", BandwidthBitPerNs=" + 
                                    bandwidthBitPerNs + 
                                    ")");
    }

    @Override
    public Link generate(NetworkDevice fromNetworkDevice, NetworkDevice toNetworkDevice, long link_multiplicity) {
        long actualDelayNs;
        if (fromNetworkDevice.isServer() || toNetworkDevice.isServer()) {
            actualDelayNs = this.intraPodDelayNs;
        } else {
            actualDelayNs = this.interPodDelayNs; 
        }
        return new PerfectSimpleLink(actualDelayNs, link_multiplicity * this.bandwidthBitPerNs);
    }

}
